package com.deli.service.impl;

import com.alibaba.fastjson.JSON;
import com.deli.entity.TestQuestion180;
import com.deli.mapper.TestQuestion180Mapper;
import com.deli.service.TestQuestion180Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedHashMap;
import java.util.List;

@Service("testQuestion180Service")
@Transactional
public class TestQuestion180ServiceImpl implements TestQuestion180Service {

    @Autowired
    private TestQuestion180Mapper testQuestion180Mapper;

    @Override
    public String getAllQuestion() throws Exception {
        List<TestQuestion180> testQuestion180s = testQuestion180Mapper.getAllQuestion();
        if (testQuestion180s == null || testQuestion180s.size() < 1) {
            throw new Exception("180题：在查询从0开始的题目时出现异常");
        }
        LinkedHashMap<String, Object> map = new LinkedHashMap<>();
        for (TestQuestion180 testQuestion180 : testQuestion180s) {
            map.put(testQuestion180.getAoption(), testQuestion180.getBoption());
        }
        return JSON.toJSONString(map);
    }

    @Override
    public String selectQuestionByStartID(int startId) {
        LinkedHashMap<String, String> map = new LinkedHashMap<>();
        List<TestQuestion180> testQuestion180s = testQuestion180Mapper.selectQuestionByStartID(startId);
        for (TestQuestion180 testQuestion180 : testQuestion180s) {
            map.put(testQuestion180.getAoption(), testQuestion180.getBoption());
        }
        return JSON.toJSONString(map);
    }
}
